// pages/details/details.js
var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    enddate:'2021-01-01',
  },
  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      enddate: e.detail.value
    })
  },
  dateok:function(){
    var that=this
    app.globalData.isShow1=false
      wx.request({
        url: app.globalData.url+'/client/deadline',
        method:'POST',
        data:{
          clientId:wx.getStorageSync('which'),
          deadline:that.data.enddate,
          state:3
        },
        header:{"content-type":"application/x-www-form-urlencoded;charset=utf-8",
                "token":app.globalData.token},
        success(res){
          console.log(res)
          app.globalData.isShow1=false
          wx.showToast({
            title: '完成',
            icon:'success'
          })
          wx.switchTab({
            url: '/pages/mortgage/mortgage',
          })
        }
      })
  },
  ok:function(){
    var that=this
    if(that.data.approvalState=="待抵押"){
      wx.request({
        url: app.globalData.url+'/client/update',
        method:'POST',
        data:{
          clientId:wx.getStorageSync('which'),
          state:4
        },
        header:{"content-type":"application/x-www-form-urlencoded;charset=utf-8",
                "token":app.globalData.token},
        success(res){
          console.log('pass')
          wx.switchTab({
            url: '/pages/lending/lending',
          })
        }
      })
    }

    else{
      wx.showToast({
        title: '未到抵押流程',
        icon:'error'
      })
    }
  },
  confirm:function(){
    var that=this
    if(that.data.approvalState=="待放款"){
      wx.request({
        url: app.globalData.url+'/client/update',
        method:'POST',
        data:{
          clientId:wx.getStorageSync('which'),
          state:5
        },
        header:{"content-type":"application/x-www-form-urlencoded;charset=utf-8",
                "token":app.globalData.token},
        success(res){
          console.log('111')
          wx.showToast({
            title: '抵押完成',
            icon:'success'
          })
          wx.navigateTo({
            url: '/pages/lended/lended',
          })
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    wx.request({
      url: app.globalData.url+'/client/check',
      method:'POST',
      data:{
        clientId:wx.getStorageSync('which')
      },
      header:{"content-type":"application/x-www-form-urlencoded;charset=utf-8",
              "token":app.globalData.token},
      success(res){
        console.log(res)
        console.log(res.data.data.approvalState)
        if(res.data.data.approvalState==1&&app.globalData.role==2){
          app.globalData.isShow3=true
        }
        if(res.data.data.approvalState==2&&app.globalData.role==1){
          app.globalData.isShow0=true
        }
        if(res.data.data.approvalState==3&&app.globalData.role==1){
          app.globalData.isShow2=true
        }
        if(res.data.data.approvalState==3&&app.globalData.role==2){
          app.globalData.isShow1=true
        }
        if(res.data.data.approvalState==3&&app.globalData.role==2&&res.data.data.deadline!=''){
          app.globalData.isShow4=true
        }
        if(res.data.data.approvalState==4&&app.globalData.role==2){
          app.globalData.isShow5=true
        }
        if(res.data.data.approvalState==1){
            res.data.data.approvalState='待审核'
        }
        if(res.data.data.approvalState==2){
          res.data.data.approvalState='待过户'
        }
        if(res.data.data.approvalState==3){
          res.data.data.approvalState='待抵押'
          
        }
        if(res.data.data.approvalState==4){
          res.data.data.approvalState='待放款'
        }

        if(res.data.data.approvalState==5){
          res.data.data.approvalState='已放款'
        }
        if(res.data.data.approvalState==6){
          res.data.data.approvalState='审核拒绝'
        }
        console.log(res)
        app.globalData.city=res.data.data.city
        app.globalData.carNumber=res.data.data.carNumber
        app.globalData.buyCarDate=res.data.data.registrationTime
        app.globalData.mileage=res.data.data.serviceLife
        that.setData({
          shenfenzheng:res.data.data.images.shenfenzheng
        })
        that.setData({
          hukouben:res.data.data.images.hukouben
        })
        that.setData({
          jiehunzheng:res.data.data.images.jiehunzheng
        })
        that.setData({
          zhengxin:res.data.data.images.zhengxin
        })
        that.setData({
          fangchanzheng:res.data.data.images.fangchanzheng
        })
        that.setData({
          xingshizheng:res.data.data.images.xingshizheng
        })
        that.setData({
          cheliangdazhao:res.data.data.images.cheliangdazhao
        })
        that.setData({
          buchongcailiao:res.data.data.images.buchongcailiao
        })
        that.setData({
          name:res.data.data.clientName,
          clientIdNumber:res.data.data.clientIdNumber,
          carNumber:res.data.data.carNumber,
          engineNumber:res.data.data.engineNumber,
          serviceLife:res.data.data.serviceLife,
          orderTime:res.data.data.orderTime.substr(0,10),
          presentWorth:res.data.data.presentWorth,
          registrationTime:res.data.data.registrationTime,
          salesman:res.data.data.salesman,
          loanAmount:res.data.data.loanAmount,
          approvalState:res.data.data.approvalState,
          bankArea:res.data.data.bankArea,
          loanTerm:res.data.data.loanTerm,
          clientName:res.data.data.clientName,
          deadline:res.data.data.deadline,
          enddate:res.data.data.deadline,
          phoneNumber:res.data.data.phoneNumber,
          carType:res.data.data.carType,
          city:res.data.data.city,
          isShow0:app.globalData.isShow0,
          isShow1:app.globalData.isShow1,
          isShow2:app.globalData.isShow2,
          isShow3:app.globalData.isShow3,
          isShow4:app.globalData.isShow4,
          isShow5:app.globalData.isShow5,
          queryState:res.data.data.queryState
        })
        app.globalData.realname=that.data.clientName
        app.globalData.idcard=that.data.clientIdNumber
        app.globalData.frameno=that.data.carNumber
        app.globalData.queryState=that.data.queryState
        console.log(app.globalData.realname)
        console.log(app.globalData.idcard)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },
  /**
   * 生命周期函数--监听页面显示
   */

  onShow: function () {
      
    },
    first:function(){
      wx.navigateTo({
        url: '/pages/first/first',
      })
    },
    second:function(){
      wx.navigateTo({
        url: '/pages/second/second',
      })
    },
    third:function(){
      wx.navigateTo({
        url: '/pages/third/third',
      })
    },
    forth:function(){
      wx.navigateTo({
        url: '/pages/forth/forth',
      })
    },
    finish:function(){
      var that=this
      if(that.data.approvalState=="待过户"){
        wx.request({
          url: app.globalData.url+'/client/update',
          method:'POST',
          data:{
            clientId:wx.getStorageSync('which'),
            state:3
          },
          header:{"content-type":"application/x-www-form-urlencoded;charset=utf-8",
                  "token":app.globalData.token},
          success(res){
            console.log('pass')
            wx.switchTab({
              url: '/pages/mortgage/mortgage',
            })
          }
        })
      }

      else{
        wx.showToast({
          title: '请等待经理审核',
          icon:'error'
        })
      }
    },
    
    pass:function(){
      var that=this
      wx.request({
        url: app.globalData.url+'/client/update',
        method:'POST',
        data:{
          clientId:wx.getStorageSync('which'),
          state:2
        },
        header:{"content-type":"application/x-www-form-urlencoded;charset=utf-8",
                "token":app.globalData.token},
        success(res){
          console.log('pass')
          wx.switchTab({
            url: '/pages/transfer/transfer',
          })
        }
      })
    },
    refuse:function(){
      var that=this
      wx.request({
        url: app.globalData.url+'/client/update',
        method:'POST',
        data:{
          clientId:wx.getStorageSync('which'),
          state:6
        },
        header:{"content-type":"application/x-www-form-urlencoded;charset=utf-8",
                "token":app.globalData.token},
        success(res){
          console.log('pass')
          wx.switchTab({
            url: '/pages/to-do/to-do',
          })
        }
      })
    },
    preview:function(e){
      let index = e.target.dataset.index;
      let that = this;
      console.log(e.target.dataset.index);
      console.log(that.data.hukouben);
      wx.previewImage({
        current: that.data.hukouben[index],
        urls: that.data.hukouben,
      })
    },
    preview1:function(e){
      let index = e.target.dataset.index;
      let that = this;
      console.log(that.data.shenfenzheng[index]);
      console.log(that.data.shenfenzheng);
      wx.previewImage({
        current: that.data.shenfenzheng[index],
        urls: that.data.shenfenzheng,
      })
    },
    preview2:function(e){
      let index = e.target.dataset.index;
      let that = this;
      console.log(that.data.jiehunzheng[index]);
      console.log(that.data.jiehunzheng);
      wx.previewImage({
        current: that.data.jiehunzheng[index],
        urls: that.data.jiehunzheng,
      })
    },
    preview3:function(e){
      let index = e.target.dataset.index;
      let that = this;
      console.log(that.data.zhengxin[index]);
      console.log(that.data.zhengxin);
      wx.previewImage({
        current: that.data.zhengxin[index],
        urls: that.data.zhengxin,
      })
    },
    preview4:function(e){
      let index = e.target.dataset.index;
      let that = this;
      console.log(that.data.fangchanzheng[index]);
      console.log(that.data.fangchanzheng);
      wx.previewImage({
        current: that.data.fangchanzheng[index],
        urls: that.data.fangchanzheng,
      })
    },
    preview5:function(e){
      let index = e.target.dataset.index;
      let that = this;
      console.log(that.data.xingshizheng[index]);
      console.log(that.data.xingshizheng);
      wx.previewImage({
        current: that.data.xingshizheng[index],
        urls: that.data.xingshizheng,
      })
    },
    preview6:function(e){
      let index = e.target.dataset.index;
      let that = this;
      console.log(that.data.cheliangdazhao[index]);
      console.log(that.data.cheliangdazhao);
      wx.previewImage({
        current: that.data.cheliangdazhao[index],
        urls: that.data.cheliangdazhao,
      })
    },
    preview7:function(e){
      let index = e.target.dataset.index;
      let that = this;
      console.log(that.data.buchongcailiao[index]);
      console.log(that.data.buchongcailiao);
      wx.previewImage({
        current: that.data.buchongcailiao[index],
        urls: that.data.buchongcailiao,
      })
    },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})